home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SOUND.SWG / 0028_Sounds In Pascal.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  544b  |  29 lines

  1. {
  2. JOERGEN DORCH
  3.  
  4.  About Sounds i Pascal - Here's how I do it:
  5. }
  6.  
  7. Function Frequency(Octave, NoteNum : Integer) : Integer;
  8. Const
  9.   Silence = 32767;
  10. Var
  11.   Oct : Integer;
  12.  
  13.   Function Power(X, Y : Real) : Real;
  14.   begin
  15.     Power := Exp(Y * Ln(X));
  16.   end;
  17.  
  18. begin
  19.   Oct := Octave - 3;
  20.   if NoteNum > 0 then
  21.     Frequency := Round(440 * Power(2, Oct + ((NoteNum - 10) / 12)))
  22.   else
  23.     Frequency := Silence;
  24. end;
  25.  
  26. {
  27. Where Octave is in the range [0..6] and NoteNum in the range [1..12],
  28. that is C = 1, C# = 2, D = 3 etc.
  29. }